
# Windows 下使用 GnuWin32 提供的 readline 库
if (CMAKE_HOST_WIN32)
    # 设置 readline 的安装路径
    set(READLINE_ROOT "C:/Program Files (x86)/GnuWin32")

    # 查找头文件路径
    find_path(READLINE_INCLUDE_DIR readline/readline.h
        PATHS "${READLINE_ROOT}/include"
    )

    # 查找库文件
    find_library(READLINE_LIBRARY
        NAMES readline
        PATHS "${READLINE_ROOT}/lib"
    )

    # 检查是否找到
    if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
            message(STATUS "Found Readline: ${READLINE_LIBRARY}")
            include_directories(${READLINE_INCLUDE_DIR})
            add_executable(testrealine main.cpp)
            target_link_libraries(testrealine ${READLINE_LIBRARY})
        else()
            message(STATUS  "Readline library not found!")
    endif()

# UNIX 系统下使用系统自带的 readline 库
elseif(CMAKE_HOST_UNIX)

    # 查找库文件
    find_library(READLINE_LIBRARY 
        NAMES readline 
        PATHS "/usr/lib/*"
    )

    if (${READLINE_LIBRARY} STREQUAL "READLINE_LIBRARY-NOTFOUND")
        message(STATUS "READLINE_LIBRARY-NOTFOUND")
        return()
    endif()
    
    message(STATUS "Found readline: ${READLINE_LIBRARY}")

    add_executable(testrealine main.cpp)
    target_link_libraries(testrealine ${READLINE_LIBRARY})

endif()
